import json

from GV import Project
from common.handle import HandleLog
from common.sendEmail import send_email_files, get_all_file
from common.thread1 import *
from common.log import GetLog

log = GetLog.get_logger()


def main(project: str):
    package = Project.get(project).get("package")
    times = Project.get(project).get("times")

    HandleLog.clearOutPut()
    HandleLog.clearLog()

    t_monkey = MonkeyThread(package, times)
    t_top = PerformanceThread(package)
    GV.exit_flag = True
    t_top.start()
    t_monkey.start()

    t_monkey.join()
    GV.exit_flag = False

    HandleLog.pullAnrLog()
    sleep(3)
    email_info = {"messages": str(Project),
                  "subject": "H37monkey测试",
                  "rec_email": "llz15565161793@163.com",
                  'attachments': get_all_file()
                  }
    send_email_files(**email_info)


if __name__ == '__main__':
    main("H37")
